package cn.hrlly.tao2shou.biz;

import android.content.Context;

import com.zhy.http.okhttp.OkHttpUtils;

import cn.hrlly.tao2shou.other.Config;
import cn.hrlly.tao2shou.callback.ApplicationListCallback;
import cn.hrlly.tao2shou.domain.ApplicationList;
import cn.hrlly.tao2shou.listener.OnApplicationListListener;
import cn.hrlly.tao2shou.utils.CacheUtil;

/**
 * User: gengliang
 * Date: 2016-01-31
 * Time: 10:47
 */

public class ApplicationListBizImpl implements ApplicationListBiz {

    private OnApplicationListListener onApplicationListListener;
    private CacheUtil cacheUtil;

    public ApplicationListBizImpl(OnApplicationListListener onApplicationListListener,Context context){
        this.onApplicationListListener=onApplicationListListener;
        this.cacheUtil=new CacheUtil(context);
    }

    @Override
    public void getNetApplicationList(ApplicationList applicationList) {
        OkHttpUtils
                .post()
                .url(Config.key_url)
                .addParams(Config.key_action,Config.action_application_list)
                .addParams(Config.key_application_type, String.valueOf(applicationList.getApplicationType()))
                .build()
                .execute(new ApplicationListCallback(onApplicationListListener));
    }

    @Override
    public void saveCacheBuyerApplicationList(ApplicationList applicationList) {
        cacheUtil.putBuyerApplication(applicationList);
    }

    @Override
    public void saveCacheSellerApplicationList(ApplicationList applicationList) {
        cacheUtil.putSellerApplication(applicationList);
    }

    @Override
    public ApplicationList getCacheBuyerApplicationList() {
        ApplicationList applicationList=cacheUtil.getBuyerApplication();
        return applicationList;
    }

    @Override
    public ApplicationList getCacheSellerApplication() {
        ApplicationList applicationList=cacheUtil.getSellerApplication();
        return applicationList;
    }
}
